package com.wanmait.wanmarecruit.webController;

import com.github.pagehelper.PageInfo;
import com.wanmait.wanmarecruit.entity.ConcernPosition;
import com.wanmait.wanmarecruit.entity.User;
import com.wanmait.wanmarecruit.mapper.ConcernPositionMapper;
import com.wanmait.wanmarecruit.service.ConcernPositionService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("web")
public class WebPersonalCollectController {

    @Resource
    private ConcernPositionService concernPositionService;

    //去个人主页收藏的职位（张佳炜）
    @RequestMapping("/personal/homepage/personalCollectJobs")
    public void goPersonalCollectJobs()
    {

    }
    //ajax通过userId和keyword查询收藏工作
    @RequestMapping("/personal/homepage/personalCollectJobsData")
    @ModelAttribute("concernPositionPageInfo")
    public PageInfo<ConcernPosition> selectAllCollectByUserId(HttpServletRequest request,Integer pageNum, String keyword)
    {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        Integer userId=user.getId();
        if(pageNum==0)
        {
            pageNum=1;
        }
        Integer pageSize=5;
        return concernPositionService.selectAllCollectByUserId(pageNum,pageSize,userId,keyword);
    }
    //ajax通过concernPositionId真删除收藏表（张佳炜）
    @RequestMapping("/personal/homepage/delectCollectJobsById")
    @ResponseBody
    public void delectCollectJobsById(Integer concernPositionId)
    {
        concernPositionService.deleteCollectJobsById(concernPositionId);
    }
    //ajax通过collectIds删除选中的收藏工作
    @RequestMapping("/personal/homepage/deleteSelectAllByCollectIds")
    @ResponseBody
    public void deleteSelectAllByCollectIds(String collectIds)
    {
        concernPositionService.deleteSelectAllByCollectIds(collectIds);
    }
}
